<%@ page import="com.biz.conf.Global" %>
<%@ include file="/jsp/taglib.jsp"%>
<%@page import="com.framework.utils.ConfigUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <%--<link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css" rel="stylesheet">

<style>
    .fileInputContainer{
        width: 150px;
        background-size: 100% 100%;
        height: 150px;
        background-repeat: no-repeat;
    }
    .fileInput{
        position: absolute;
        top:30%;
        left:30%;
    }.upload_pic {
         height: 70px;
         width:70px;
         position: relative;
         cursor: pointer;
         color: #ccbe9e;
         background: #fff;
         overflow: hidden;
         display: inline-block;
         *display: inline;
         *zoom: 1;
     }
    .upload_pic input {
        position: absolute;
        height:100%;
        width:100%;
        right: 0;
        top: 0;
        opacity: 0;
        filter: alpha(opacity=0);
        cursor: pointer
    }
    .upload_pic:hover {
        color: #ccbe9e;
        background: #fff;
        text-decoration: none
    }
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>商户信息修改</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal m-t" id="signupForm">
                        <input id="sysUser_id" value="${sysUser.id}" name="sysUser.id" type="hidden">
                        <input value="${identity_code}" name="sysUser.identityCode" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">性别：</label>
                            <div class="col-sm-8">
                                <select id="sysUser_sex" data-placeholder="选择性别..." class="chosen-select"  value="${sysUser.sex}" name="sysUser.sex" class="form-control">
                                    <option value="1">男</option>
                                    <option value="0">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机号码：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_phone" value="${sysUser.phone}" name="sysUser.phone" class="form-control" type="phone" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">邮箱：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_email" value="${sysUser.email}" name="sysUser.email" class="form-control" type="email">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_notes" value="${sysUser.notes}" name="sysUser.notes" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户LOGO：</label>
                            <div class="col-sm-4">
                                <!--上传logo-->
                                <div class="dtupload">
                                    <a href="javascript:" class="upload_pic" style="height:80px;"><input type="file" name="fileToUpload" id="fileToUpload1" onChange="uploadFile('fileToUpload1','imgUpdate','shopPicId');">
                                        <img  id="imgUpdate" src="${pageContext.request.contextPath}/resources/image/logopic1.png" width="100%"/>
                                        <input type="hidden" id="shopPicId" name="sysUser.logoUrl">
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户名称：</label>
                            <div class="col-sm-8">
                                <input id="brand_name" value="${brand.name}" name="sysUser.brandName" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">省市：</label>
                            <div class="col-sm-4">
                                <select id="brand_province" data-placeholder="选择省份..." class="chosen-select"  value="${brand.province}"  onchange="loadCity(this.value)"  name="sysUser.province" class="form-control">

                                </select>
                            </div>
                            <div class="col-sm-4">
                                <select id="brand_city"  data-placeholder="选择城市..." class="chosen-select"   value="${brand.city}" name="sysUser.city" class="form-control">

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细地址：</label>
                            <div class=" col-sm-9">
                                <input type="text" id="brand_address"  name="sysUser.address" placeholder="请输入详细地址" class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">内容：</label>
                            <div class=" col-sm-9">
                                <!-- 加载编辑器的容器 -->
                                <script id="container" name="content" style="height:300px" type="text/plain">
                                </script>
                                <input id="brand_introduction" name="sysUser.introduction" type="hidden">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                                <button id="btn_close"  class="btn btn-primary" type="button">关闭</button>
                                <%--<button id="transmit"  class="btn btn-primary" type="button">给父页面传值</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/layer2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/ajaxfileupload.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.all.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script>
    $(function(){
        loadPr();
        $('#sysUser_sex').chosen({
            no_results_text : "未找到此选项!",
            width:"100%"
        });
    });
    <!-- 实例化编辑器; -->
    var ue = UE.getEditor('container');
    <!-- 自定义上传图片-->
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadfile') {
            return '${ctx}/ue/uploadImageForUE.ac';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    };
    var picPath='<%=ConfigUtil.get("OSSURL")%>';
    var id='${identity_code}';
    //对编辑器的操作最好在编辑器ready之后再做
    ue.ready(function() {
        //设置编辑器的内容
        ue.setContent('');
        //获取html内容，返回: <p>hello</p>
        var html = ue.getContent();
        //获取纯文本内容，返回: hello
        var txt = ue.getContentTxt();
        if(id!=null&&id!=''&&id!=undefined)//如果是编辑，读取数据
        {
            loadForEdit(id);
        }


    });
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var picPath='<%=Global.getConfig("OSSURL")%>';
    //编辑回写
    function loadForEdit(id) {
        var url="${ctx}/merchant/getById.ac";
        $.ajax({
            url:url,
            data:{id:id},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                $("#brand_brand_code").val(data.brandCode);//code
                $("#brand_name").val(data.name);//名称
                $("#shopPicId").val(data.logoUrl);//logo
                $("#imgUpdate").attr("src",picPath+data.logoUrl);

                $("#brand_address").val(data.address);//地址
               // $("#brand_telephone").val(data.telephone);//联系方式
                ue.setContent(data.introduction);//编辑框内容
            },
            error : function() {
                alert("异常！");
            }
        });
    }

    function loadPr()
    {
        $.ajax( {
            url:'${pageContext.request.contextPath}/area/getArea.ac',// 跳转到 action
            data:{},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                areaData=data;
                var html='<option value="">请选择</option>';
                for(var i=0;i<data.pro.length;i++)
                {

                    html+='<option value="'+data.pro[i].id+'">'+data.pro[i].text+'</option>';

                }
                $("#brand_province").html(html);
                $('#brand_province').chosen({
                    no_results_text : "未找到此选项!",
                    width:"100%"
                });

                if('${brand.province}'!=null&&'${brand.province}'!=''&&'${brand.province}'!=undefined)
                {

                    // $("#agent_province option[value='${brand.province}']").attr("selected","selected");
                    //  $("#agent_province").chosen();
                    $("#brand_province").val('${brand.province}');
                    $("#brand_province").trigger("chosen:updated");
                    loadCity('${brand.province}');
                }
            },
            error : function() {
                alert("加载代理商列表失败！");
            }
        });
    }
    function loadCity(id)
    {
        //  var id=obj.value;
        var data=areaData;
        var html='<option value="">请选择</option>';
        for(var i=0;i<data.city.length;i++)
        {
            if(data.city[i].pid==id)
            {
                html+='<option value="'+data.city[i].id+'">'+data.city[i].text+'</option>';
            }
        }
        $("#brand_city").html(html);
        $('#brand_city').chosen({
            no_results_text : "未找到此选项!",
            width:"100%"
        });
        $("#brand_city").trigger("chosen:updated");
        if('${brand.city}'!=null&&'${brand.city}'!=''&&'${brand.city}'!=undefined&&id=='${brand.province}')
        {
            $("#brand_city").val('${brand.city}');
            //   $("#agent_city option[value='${brand.city}']").attr("selected","selected");
            // $("#agent_city").chosen();
            $("#brand_city").trigger("chosen:updated");
        }


    }
    //给父页面传值
    $('#transmit').on('click', function(){

       // parent(".J_iframe").$("#spancc").text("5");
        alert(parent.$('#spancc').text());
        $(parent.window.frames["iframe8"].document).find("#spancc").html("我被改变了");
        $(parent.window.frames["iframe8"].document).find("#exampleTablePagination").bootstrapTable('refresh');
        //parent.$('#spancc').html('我被改变了');
        parent.layer.close(index);
    });

    //关闭iframe
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });
    function doSubmit()
    {
        var sex=$("#sysUser_sex").val();
        var phone=$("#sysUser_phone").val();
        var email=$("#sysUser_email").val();
        var notes=$("#sysUser_notes").val();
        var brand_name=$("#brand_name").val();
        var container=ue.getContent();//编辑框内容
        $("#brand_introduction").val(container);
        var isOk=true;
        if(sex==null||sex==undefined||sex==''){alert("请选择性别");isOk= false;}
        if(phone==null||phone==undefined||phone==''){alert("请输入手机号码");isOk= false;}
        if(email==null||email==undefined||email==''){alert("请输入邮箱");isOk= false;}
        if(brand_name==null||brand_name==undefined||brand_name==''){alert("请输入商户名称");isOk= false;}
        if(isOk){
            $.ajax( {
                url:'${pageContext.request.contextPath}/sysUser/updateUser.ac?type=3',// 跳转到 action
                data:$("#signupForm").serialize(),
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    if(data=="success")
                    {
                        alert("操作成功！");

                        parent.layer.close(index);
                    }else{
                        alert(data);
                    }
                },
                error : function() {
                    alert("操作失败！");
                }
            });
        }
    }
    function uploadFile(obj,id,picId){//上传图片
        var labid = "";
        //var detailId = $("#detailId").val();
        //$("#"+id).css("background","url(${pageContext.request.contextPath}/resources/assets/images/waiting.gif) no-repeat 0 0/100% 100%");
        $.ajaxFileUpload({
            url: '${pageContext.request.contextPath}/common/doUploadFile.ac',
            secureuri: false,
            type:'post',
            fileElementId: obj,
            dataType: 'text',
            success: function(data, status) {

                var img=JSON.parse(data);
                $("#"+id).attr("src",picPath+img.path);
                $("#"+picId).val(img.path);

            },
            error: function(data, status, e) {
                alert(e);
            }
        });
    }
</script>

</body>

</html>

